<?php
namespace App\Http\Controllers\Admin;

use App\Services\Admin\FwCntService;
use Illuminate\Http\Request;

class FwCntController extends BaseController
{
    //服务详情

    public function __construct(FwCntService $service)
    {
        $this->db = $service;
    }

    /**
     * 列表
     */
    public function getIndex(Request $request)
    {
        $pages['start'] = $request->post('pageStart', 0);
        $pages['limit'] = $request->post('pageLimit', 10);
        $pas['fwid'] = $request->post('fwid', 0);
        $res = $this->db->getIndex($pages, $pas);
        if ($res['code']!=0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }

    //修改
    public function modify(Request $request)
    {
        $id = $request->post('id', 0);
        $pas['type'] = $request->post('type', 0);
        $pas['cnt'] = $request->post('cnt', '');
        if ($id) {
            $res = $this->db->modify($id, $pas);
        } else {
            $res = $this->db->add($pas);
        }
        if ($res['code']!=0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }

    //删除
    public function del(Request $request)
    {
        $id = $request->post('id', 0);
        $res = $this->db->del($id);
        if ($res['code']!=0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }
}